home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume7 / rvi / part4 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  22.2 KB

  1. Subject:  v07i006:  Vi front-end for remote editing, Part04/04
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: Alan Klietz <ihnp4!dicome!mn-at1!alan>
  6. Mod.sources: Volume 7, Issue 6
  7. Archive-name: rvi/Part04
  8.  
  9. #!/bin/sh
  10. # This is a shell archive.  Remove anything before this line,
  11. # then unpack it by saving it in a file and typing "sh file".
  12. # Wrapped by mirror!rs on Wed Aug 27 00:12:10 EDT 1986
  13.  
  14. # Exit status; set to 1 on "wc" errors or if would overwrite.
  15. STATUS=0
  16. # Contents:  rv_where.c rv_word.c rv_xmit.c rv_yank.c rvi.1 rvtest.c
  17. #    todo zero.c MANIFEST
  18.  
  19. echo x - rv_where.c
  20. if test -f rv_where.c ; then
  21.     echo rv_where.c exists, putting output in $$rv_where.c
  22.     OUT=$$rv_where.c
  23.     STATUS=1
  24. else
  25.     OUT=rv_where.c
  26. fi
  27. sed 's/^XX//' > $OUT <<'@//E*O*F rv_where.c//'
  28. XX#include "rv.h"
  29. XX#include <ctype.h>
  30.  
  31. XXvoid
  32. XXread_where_mod(cmd, specified_count, cmd_count)
  33. XX/*
  34. XX * Read in where modifier, override old count if specified
  35. XX */
  36. XXINT    cmd;              /* Previous cmd_character */
  37. XXboolean    specified_count;  /* TRUE if count was specified  */
  38. XXINT    cmd_count;      /* Command count, default 1 */
  39. XX{
  40. XX    INT    c;
  41. XX    INT    count;
  42. XX    void    where_mod();
  43.  
  44. XX    if (read_cmd(&c, &count)) {
  45. XX        specified_count = TRUE;
  46. XX        cmd_count = count;
  47. XX    }
  48. XX    /*
  49. XX     * Doubled character means single line (internally stored as '\0')
  50. XX     */
  51. XX    if (c == cmd)
  52. XX        c = '\0';
  53. XX    where_mod(c, specified_count, cmd_count, FALSE);
  54. XX}
  55.  
  56.  
  57. XXvoid
  58. XXwhere_mod(c, specified_count, cmd_count, cmdflag)
  59. XX/*
  60. XX * Set the (row,col) pairs to cover the range of text specified by
  61. XX * the where modifier.  The caller gets the pairs via the screen structure.
  62. XX *
  63. XX * Screen structure,
  64. XX *
  65. XX *    sc->sc_firstline    First line # of range
  66. XX *    sc->sc_firstcol        First column # of range
  67. XX *
  68. XX *    sc->sc_lastline        Last line # of range
  69. XX *    sc->sc_lastcol        Last column # of range
  70. XX *
  71. XX *    sc->sc_validcol        If column # if valid (otherwise
  72. XX *                the range covers whole lines)
  73. XX */
  74. XXINT    c;            /* Command character */
  75. XXboolean    specified_count;    /* TRUE if count was specified */
  76. XXINT    cmd_count;        /* Command count, default 1*/
  77. XXboolean    cmdflag;        /* TRUE if this is a cursor movement command */
  78. XX{
  79. XX    register struct    sc_screen *sc;
  80. XX    boolean forward_back(), word_search(), search();
  81. XX    static    INT    last_searchdir = 1;
  82.  
  83. XX    sc = &screen;
  84. XX    sc->sc_firstline = sc->sc_lineno;
  85. XX    sc->sc_firstcol = sc->sc_column;
  86. XX    sc->sc_lastline = sc->sc_lineno;
  87. XX    sc->sc_lastcol = sc->sc_column;
  88. XX    sc->sc_validcol = TRUE;
  89.  
  90. XX    switch (c) {
  91.  
  92. XXcase 'h':
  93. XXcase '\b':
  94. XX#ifdef USG
  95. XXcase KEY_LEFT:
  96. XX#endif
  97. XX    /*
  98. XX     * Left cursor
  99. XX     */
  100. XX    sc->sc_firstcol -= cmd_count;
  101. XX    sc->sc_lastcol--;
  102. XX    break;
  103.  
  104. XXcase 'l':
  105. XXcase ' ':
  106. XX#ifdef USG
  107. XXcase KEY_RIGHT:
  108. XX#endif
  109. XX    /*
  110. XX     * Right cursor
  111. XX     */
  112. XX    sc->sc_lastcol += cmd_count-1;
  113. XX    break;
  114.  
  115.  
  116. XXcase 'k':
  117. XXcase '-':
  118. XXcase CTRL(P):
  119. XX#ifdef USG
  120. XXcase KEY_UP:
  121. XX#endif
  122. XX    /*
  123. XX     * Up cursor
  124. XX     */
  125. XX    sc->sc_validcol = FALSE;
  126. XX    sc->sc_firstline -= cmd_count;
  127. XX    break;
  128.  
  129. XXcase 'j':
  130. XXcase '\n':
  131. XXcase '\r':
  132. XXcase '+':
  133. XXcase CTRL(N):
  134. XX#ifdef USG
  135. XXcase KEY_DOWN:
  136. XX#endif
  137. XX    /*
  138. XX     * Down cursor
  139. XX     */
  140. XX    sc->sc_validcol = FALSE;
  141. XX    sc->sc_lastline += cmd_count;
  142. XX    break;
  143.  
  144. XXcase '\0':
  145. XX    /*
  146. XX     * Repeated character (line count)
  147. XX     */
  148. XX    sc->sc_validcol = FALSE;
  149. XX    sc->sc_lastline += cmd_count-1;
  150. XX    break;
  151.  
  152. XXcase '0':
  153. XX    /*
  154. XX     * Beginning of line
  155. XX     */
  156. XX    sc->sc_lastcol--;
  157. XX    sc->sc_firstcol = 0;
  158. XX    break;
  159.  
  160. XXcase '^':
  161. XXcase '_':
  162. XX    /*
  163. XX     * First nonwhite char
  164. XX     */
  165. XX    sc->sc_lastcol--;
  166. XX    sc->sc_firstcol = 0;
  167. XX    while (isspace(sc->sc_curline->li_text[sc->sc_firstcol]) &&
  168. XX            sc->sc_firstcol != sc->sc_lastcol)
  169. XX        sc->sc_firstcol++;
  170. XX    if (sc->sc_firstcol > sc->sc_lastcol)
  171. XX        sc->sc_lastcol = sc->sc_firstcol;
  172. XX    break;
  173.  
  174. XXcase '$':
  175. XX    /*
  176. XX     * End of line
  177. XX     */
  178. XX    sc->sc_lastcol = sc->sc_curline->li_width-1;
  179. XX    break;
  180.  
  181. XXcase ',': 
  182. XXcase ';':
  183. XXcase 'f':
  184. XXcase 'F':
  185. XXcase 't':
  186. XXcase 'T':
  187. XX    /*
  188. XX     * Search for character forward and backward
  189. XX     */
  190. XX    if (!forward_back(c, cmd_count))
  191. XX        goto error;
  192. XX    break;
  193. XX    
  194. XXcase 'w':
  195. XXcase 'W':
  196. XXcase 'b':
  197. XXcase 'B':
  198. XXcase 'e':
  199. XXcase 'E':
  200. XX    /*
  201. XX     * Go to the next word
  202. XX     */
  203. XX    if (!word_search(c, cmd_count, cmdflag))
  204. XX        goto error;
  205. XX    break;
  206.  
  207. XXcase 'H':
  208. XX#ifdef USG
  209. XXcase KEY_HOME:
  210. XX#endif
  211. XX    /*
  212. XX     * Home line
  213. XX     */
  214. XX    sc->sc_validcol = FALSE;
  215. XX    sc->sc_firstline = sc->sc_lineno - (sc->sc_curline-sc->sc_topline) +
  216. XX        cmd_count-1;
  217. XX    break;
  218.  
  219. XXcase 'L':
  220. XX#ifdef USG
  221. XXcase KEY_LL:
  222. XX#endif
  223. XX    /*
  224. XX     * Last line
  225. XX     */
  226. XX    sc->sc_validcol = FALSE;
  227. XX    sc->sc_lastline = sc->sc_lineno + (sc->sc_botline-sc->sc_curline) -
  228. XX        cmd_count+1;
  229. XX    break;
  230.  
  231. XXcase 'G':
  232. XX    /*
  233. XX     * Goto line #
  234. XX     */
  235. XX    sc->sc_validcol = FALSE;
  236. XX    if (!specified_count)
  237. XX        cmd_count = file.fi_numlines;
  238. XX    if (cmd_count < sc->sc_lineno)
  239. XX        sc->sc_firstline = cmd_count;
  240. XX    else
  241. XX        sc->sc_lastline = cmd_count;
  242. XX    break;
  243.  
  244. XXcase '|':
  245. XX    /*
  246. XX     * Goto column #
  247. XX     */
  248. XX    cmd_count = file_column(sc->sc_curline->li_text, cmd_count-1);
  249. XX    if (cmd_count == sc->sc_column)
  250. XX        goto error;
  251. XX    if (cmd_count < sc->sc_column)
  252. XX        sc->sc_firstcol = cmd_count;
  253. XX    else
  254. XX        sc->sc_lastcol = cmd_count;
  255. XX    break;
  256.  
  257. XXcase '\'':
  258. XX    /*
  259. XX     * Goto mark
  260. XX     */
  261. XX    c = getch();
  262. XX    xmit_ed("'%c\n", c);
  263. XX    xmit_sync();
  264. XX    xmit_ed(".=\n");
  265. XX    if (recv_sync(FALSE)) {
  266. XX        char buf[32];
  267.  
  268. XX        sc->sc_validcol = FALSE;
  269. XX        fgets(buf, 31, file.fi_fpin);
  270. XX        if ((c = atoi(buf)) > 0)
  271. XX            if (c < sc->sc_lineno)
  272. XX                sc->sc_firstline = c;
  273. XX            else
  274. XX                sc->sc_lastline = c;
  275. XX    } else
  276. XX        goto error;
  277. XX    break;
  278. XX    
  279. XXcase '/':
  280. XX    /*
  281. XX     * Search forward
  282. XX     */
  283. XX    mvaddch(LINES-1, 0, '/');
  284. XX    last_searchdir = 1;
  285. XX    if (!search(1, rv_getline(), cmdflag)) {
  286. XX        errflag = 1;
  287. XX        return;
  288. XX    }
  289. XX    errflag = cmdflag;
  290. XX    break;
  291.  
  292. XXcase '?':
  293. XX    /*
  294. XX     * Search backward
  295. XX     */
  296. XX    mvaddch(LINES-1, 0, '?');
  297. XX    last_searchdir = -1;
  298. XX    if (!search(-1, rv_getline(), cmdflag)) {
  299. XX        errflag = 1;
  300. XX        return;
  301. XX    }
  302. XX    errflag = cmdflag;
  303. XX    break;
  304.  
  305. XXcase 'N':
  306. XX    /*
  307. XX     * Reverse last search
  308. XX     */
  309. XX    if (!search(last_searchdir > 0 ? -1 : 1, "", cmdflag)) {
  310. XX        errflag = 1;
  311. XX        return;
  312. XX    }
  313. XX    errflag = cmdflag;
  314. XX    break;
  315.  
  316. XXcase 'n':
  317. XX    /*
  318. XX     * Repeat last search
  319. XX     */
  320. XX    if (!search(last_searchdir, "", cmdflag)) {
  321. XX        errflag = 1;
  322. XX        return;
  323. XX    }
  324. XX    errflag = cmdflag;
  325. XX    break;
  326.  
  327. XXcase '[':
  328. XX    /*
  329. XX     * Search backward for C function
  330. XX     */
  331. XX    if (getch() != '[' || !search(-1, "^{", cmdflag)) {
  332. XX        move(LINES-1, 0);
  333. XX        clrtoeol();
  334. XX        move_cursor(sc->sc_lineno, sc->sc_column);
  335. XX        goto error;
  336. XX    }
  337. XX    errflag = cmdflag;
  338. XX    break;
  339.  
  340. XXcase ']':
  341. XX    /*
  342. XX     * Search forward for C function
  343. XX     */
  344. XX    if (getch() != ']' || !search(1, "^{", cmdflag)) {
  345. XX        move(LINES-1, 0);
  346. XX        clrtoeol();
  347. XX        move_cursor(sc->sc_lineno, sc->sc_column);
  348. XX        goto error;
  349. XX    }
  350. XX    errflag = cmdflag;
  351. XX    break;
  352.  
  353.  
  354. XXdefault:
  355. XX    /*
  356. XX     * Unknown where modifier
  357. XX     */
  358. XX    goto error;
  359.  
  360.  
  361. XX    }  /* End of switch */
  362.  
  363. XX    if (errflag)
  364. XX        return;
  365. XX    /*
  366. XX     * Consistency checks
  367. XX     */
  368. XX    if (sc->sc_validcol) {
  369. XX        if (sc->sc_firstcol < 0) {
  370. XX            if (sc->sc_column == 0)
  371. XX                goto error;
  372. XX            sc->sc_firstcol = 0;
  373. XX        }
  374. XX        if (sc->sc_lastcol < 0) 
  375. XX            goto error;
  376. XX        if (sc->sc_firstline == sc->sc_lineno)
  377. XX            if (sc->sc_firstcol >= sc->sc_curline->li_width)
  378. XX                goto error;
  379. XX        if (sc->sc_lastline == sc->sc_lineno)
  380. XX            if (sc->sc_lastcol >= sc->sc_curline->li_width) {
  381. XX                if (sc->sc_column == sc->sc_curline->li_width)
  382. XX                    goto error;
  383. XX                sc->sc_lastcol = sc->sc_curline->li_width;
  384. XX            }
  385. XX    }
  386. XX    if (sc->sc_firstline > 0 && sc->sc_firstline <= file.fi_numlines &&
  387. XX        sc->sc_lastline > 0 &&  sc->sc_lastline <= file.fi_numlines)
  388. XX        return;
  389.  
  390. XXerror:
  391. XX    errflag = 1;
  392. XX    flash();
  393. XX    return;
  394. XX}
  395. @//E*O*F rv_where.c//
  396. chmod u=rw,g=rw,o=rw $OUT
  397.  
  398. echo x - rv_word.c
  399. if test -f rv_word.c ; then
  400.     echo rv_word.c exists, putting output in $$rv_word.c
  401.     OUT=$$rv_word.c
  402.     STATUS=1
  403. else
  404.     OUT=rv_word.c
  405. fi
  406. sed 's/^XX//' > $OUT <<'@//E*O*F rv_word.c//'
  407. XX#include "rv.h"
  408. XX#include <ctype.h>
  409.  
  410. XXextern boolean change_flag;    /* The current command is a change cmd */
  411.  
  412. XXstatic INT matchtype;
  413.  
  414. XXstatic boolean
  415. XXisword(c, bigflag)
  416. XX/*
  417. XX * Return TRUE if c is part of a word
  418. XX */
  419. XXINT c;
  420. XXboolean bigflag;
  421. XX{
  422. XX    INT oldmatchtype;
  423.  
  424. XX    if (bigflag)
  425. XX        return (!isspace(c));
  426. XX    oldmatchtype = matchtype;
  427. XX    if (isalpha(c) || isdigit(c) || c == '_') {
  428. XX        matchtype = 1;
  429. XX        return (oldmatchtype != 2);
  430. XX    }
  431. XX    if (!isspace(c)) {
  432. XX        matchtype = 2;
  433. XX        return (oldmatchtype != 1);
  434. XX    }
  435. XX    matchtype = 0;
  436. XX    return FALSE;
  437. XX}
  438. XX    
  439.  
  440.  
  441. XXboolean
  442. XXword_search(c, cmd_count, cmdflag)
  443. XX/*
  444. XX * Scan forward and backward for words
  445. XX */
  446. XXINT c;
  447. XXINT cmd_count;
  448. XXboolean cmdflag;    /* TRUE if this is a cursor movement command */
  449. XX{
  450. XX    register INT i, len, method;
  451. XX    register char *s;
  452. XX    register struct sc_screen *sc;
  453. XX    INT    direction = 1;
  454. XX    boolean big_word = FALSE, end_word = FALSE, newline_flag = FALSE;
  455.  
  456. XX    sc = &screen;
  457.  
  458. XX    switch (c) {
  459. XXcase 'w':
  460. XX    /*
  461. XX     * Scan forward for a word
  462. XX     */
  463. XX    direction = 1;
  464. XX    big_word = FALSE;
  465. XX    break;
  466.  
  467. XXcase 'W':
  468. XX    /*
  469. XX     * Scan forward for a big word
  470. XX     */
  471. XX    direction = 1;
  472. XX    big_word = TRUE;
  473. XX    break;
  474.  
  475. XXcase 'b':
  476. XX    /*
  477. XX     * Scan backward for a word
  478. XX     */
  479. XX    direction = -1;
  480. XX    big_word = FALSE;
  481. XX    break;
  482.  
  483. XXcase 'B':
  484. XX    /*
  485. XX     * Scan backward for a big word
  486. XX     */
  487. XX    direction = -1;
  488. XX    big_word = TRUE;
  489. XX    break;
  490.  
  491. XXcase 'e':
  492. XX    /*
  493. XX     * Scan forward for the end of a word
  494. XX     */
  495. XX    direction = 1;
  496. XX    big_word = FALSE;
  497. XX    end_word = TRUE;
  498. XX    break;
  499.  
  500. XXcase 'E':
  501. XX    /*
  502. XX     * Scan forward for the end of a big word
  503. XX     */
  504. XX    direction = 1;
  505. XX    big_word = TRUE;
  506. XX    end_word = TRUE;
  507. XX    break;
  508.  
  509. XXdefault:
  510. XX    return FALSE;
  511.  
  512. XX    } /* End switch */
  513.  
  514.  
  515. XX    s = sc->sc_curline->li_text;
  516. XX    len = sc->sc_curline->li_width;
  517. XX    sc->sc_validcol = TRUE;
  518. XX    i = sc->sc_column;
  519. XX    for (; cmd_count > 0; --cmd_count) {
  520. XX        /*
  521. XX         * Build a search algorithm
  522. XX         */
  523. XX        matchtype = 0;
  524. XX        if (len <= 0)
  525. XX            goto beyondline;
  526. XX        if (newline_flag) {
  527. XX            method = isword(s[i], big_word) ? 1 : 0;
  528. XX            newline_flag = FALSE;
  529. XX        } else {
  530. XX            INT temptype;
  531.  
  532. XX            method = isword(s[i], big_word) ? 2 : 0;
  533. XX            temptype = matchtype;
  534. XX            if (direction > 0 && i < len-1 ||
  535. XX                    direction < 0 && i > 0)
  536. XX                method |= isword(s[i+direction], big_word) ?
  537. XX                    1 : 0;
  538. XX            matchtype = temptype;
  539. XX        }
  540. XX        if (direction < 0 || end_word)
  541. XX            method |= 4;
  542. XX        if (method < 4 && change_flag)
  543. XX            method = 4;  /* Emulating a vi kludge.. */
  544. XX        else
  545. XX            switch (method) {
  546. XX    case 0:
  547. XX    case 1:            method = 2;
  548. XX                break;
  549. XX    case 2:
  550. XX    case 3:            method = 3;
  551. XX                break;
  552. XX    case 7:            method = 4;
  553. XX                break;
  554. XX    case 4:
  555. XX    case 5:            method = 6;
  556. XX                break;
  557. XX    case 6:            method = 7;
  558. XX                break;
  559. XX            }
  560. XX        /*
  561. XX         * Execute the search algorithm 
  562. XX         */
  563. XX        if (method & 1)
  564. XX            while (isword(s[i], big_word)) {
  565. XX                i += direction;
  566. XX                if (i < 0 || i >= len)
  567. XX                    goto beyondline;
  568. XX            }
  569. XX        if (method & 2)
  570. XX            while (!isword(s[i], big_word)) {
  571. XX                i += direction;
  572. XX                if (i < 0 || i >= len)
  573. XX                    goto beyondline;
  574. XX            }
  575. XX        if (method & 4)
  576. XX            for (;;) {
  577. XX                i += direction;
  578. XX                if (i < 0 || i >= len ||
  579. XX                        !isword(s[i], big_word)) {
  580. XX                    i -= direction;
  581. XX                    break;
  582. XX                }
  583. XX            }
  584. XX        continue;
  585. XXbeyondline:
  586. XX        if (cmdflag) {
  587. XX            move_abs_cursor(sc->sc_lineno+direction, 0);
  588. XX            s = sc->sc_curline->li_text;
  589. XX            len = sc->sc_curline->li_width;
  590. XX            sc->sc_firstline = sc->sc_lineno;
  591. XX            sc->sc_lastline = sc->sc_lineno;
  592. XX            if (errflag)
  593. XX                break;
  594. XX            if (len == 0 || direction > 0)
  595. XX                i = 0;
  596. XX            else
  597. XX                i = len-1;
  598. XX            sc->sc_column = sc->sc_firstcol = sc->sc_lastcol = i;
  599. XX            sc->sc_validcol = TRUE;
  600. XX            ++cmd_count;
  601. XX            newline_flag = TRUE;
  602. XX        } else
  603. XX            break;
  604. XX    }
  605. XX    if (direction >= 0) {
  606. XX        sc->sc_lastcol = i;
  607. XX        if (!cmdflag && method < 4 && !change_flag)
  608. XX            sc->sc_lastcol--;
  609. XX    } else {
  610. XX        if (!cmdflag)
  611. XX            sc->sc_lastcol--;
  612. XX        sc->sc_firstcol = i;
  613. XX    }
  614. XX    return (sc->sc_firstcol <= sc->sc_lastcol);
  615. XX}
  616. @//E*O*F rv_word.c//
  617. chmod u=rw,g=rw,o=rw $OUT
  618.  
  619. echo x - rv_xmit.c
  620. if test -f rv_xmit.c ; then
  621.     echo rv_xmit.c exists, putting output in $$rv_xmit.c
  622.     OUT=$$rv_xmit.c
  623.     STATUS=1
  624. else
  625.     OUT=rv_xmit.c
  626. fi
  627. sed 's/^XX//' > $OUT <<'@//E*O*F rv_xmit.c//'
  628. XX#include "rv.h"
  629.  
  630. XXvoid
  631. XXxmit_curline()
  632. XX/*
  633. XX * Transmit the current line, if modified
  634. XX */
  635. XX{
  636. XX    register struct sc_screen *sc;
  637. XX    register struct li_line  *line;
  638.  
  639. XX    sc = &screen;
  640. XX    if (sc->sc_origline.li_text != NULL) {
  641. XX        free(sc->sc_origline.li_text);
  642. XX        sc->sc_origline.li_text = NULL;
  643. XX        line = sc->sc_curline;
  644. XX        xmit_ed("%dc\n", sc->sc_lineno);
  645. XX        if (strcmp(line->li_text, ".") == 0)
  646. XX            fputs("\\.", file.fi_fpout);
  647. XX        else
  648. XX            fputs(line->li_text, file.fi_fpout);
  649. XX        fputs("\n.\n", file.fi_fpout);
  650. XX        file.fi_modified = TRUE;
  651. XX        if (set_debug > 1)
  652. XX            fputs("\007", stderr);
  653. XX    }
  654. XX}
  655.  
  656.  
  657. XX/*VARARGS1*/
  658. XXvoid
  659. XXxmit_ed(txt, arg1, arg2, arg3, arg4, arg5)
  660. XX/*
  661. XX * Printf the string to ed
  662. XX */
  663. XXchar *txt, *arg1, *arg2, *arg3, *arg4, *arg5;
  664. XX{
  665. XX    char buf[512];
  666.  
  667. XX    sprintf(buf, txt, arg1, arg2, arg3, arg4, arg5);
  668. XX    fputs(buf, file.fi_fpout);
  669. XX}
  670. @//E*O*F rv_xmit.c//
  671. chmod u=rw,g=rw,o=rw $OUT
  672.  
  673. echo x - rv_yank.c
  674. if test -f rv_yank.c ; then
  675.     echo rv_yank.c exists, putting output in $$rv_yank.c
  676.     OUT=$$rv_yank.c
  677.     STATUS=1
  678. else
  679.     OUT=rv_yank.c
  680. fi
  681. sed 's/^XX//' > $OUT <<'@//E*O*F rv_yank.c//'
  682. XX#include "rv.h"
  683.  
  684. XXINT    yank_shift = 9;  /* Shift count for numbered yank buffers */
  685. XXINT    yank_cmd;     /* "x letter */
  686.  
  687. XXINT
  688. XXchar_to_yank(c)
  689. XX/*
  690. XX * Convert a character to a yank ordinal
  691. XX */
  692. XXregister INT c;
  693. XX{
  694. XX    if (c == ' ')
  695. XX        return 0;
  696. XX    else if (c >= '1' && c <= '9')
  697. XX        c = (yank_shift - (c - '0')) % 9 + 1;
  698. XX    else if (c >= 'a' && c <= 'z')
  699. XX        c = c - 'a' + 10;
  700. XX    else if (c == '.')
  701. XX        return NUM_YANK_BUFS-2;
  702. XX    else {
  703. XX        if (c != '$')
  704. XX            errflag = 1;
  705. XX        return NUM_YANK_BUFS-1;
  706. XX    }
  707. XX    return c;
  708. XX}
  709.  
  710.  
  711. XXvoid
  712. XXyank()
  713. XX/*
  714. XX * Yank text between first/last marks. 
  715. XX * If more than 1 line, text is written to a temp file using ed.
  716. XX */
  717. XX{
  718. XX    register struct li_line      *line;
  719. XX    register struct ya_yank   *yank;
  720. XX    register struct sc_screen *sc;
  721. XX    INT    indx;
  722.  
  723. XX    sc = &screen;
  724.  
  725. XX    indx = char_to_yank(yank_cmd);
  726. XX    if (errflag) {
  727. XX        flash();
  728. XX        return;
  729. XX    }
  730. XX    yank = &yank_array[indx];
  731. XX    line = sc->sc_curline;
  732.  
  733. XX    /*
  734. XX     * Three cases:  lines, columns, or both
  735. XX     */
  736. XX    if (sc->sc_validcol) { /* If columns */
  737. XX        if (sc->sc_firstline != sc->sc_lastline) { /* If both */
  738. XX            botprint(TRUE,
  739. XX                "Cant yank columns within multiple lines yet.\n");
  740. XX            return;
  741. XX        }
  742. XX        yank->ya_type = YANK_COLS;
  743. XX        yank->ya_width = sc->sc_lastcol - sc->sc_firstcol + 1;
  744. XX        yank->ya_numlines = 0;
  745. XX        if (yank->ya_text)
  746. XX            free(yank->ya_text);
  747. XX        yank->ya_text = xalloc(yank->ya_width+1);
  748. XX        strncpy(yank->ya_text, &line->li_text[sc->sc_firstcol], yank->ya_width);
  749. XX        yank->ya_text[yank->ya_width] = '\0';
  750. XX    }
  751. XX    else { /* If lines */
  752. XX        if (sc->sc_firstline == sc->sc_lastline) {
  753. XX            /*
  754. XX             * Simple case - yank line
  755. XX             */
  756. XX            yank->ya_type = YANK_SINGLE;
  757. XX            yank->ya_width = 0;
  758. XX            yank->ya_numlines = 1;
  759. XX            if (yank->ya_text)
  760. XX                free(yank->ya_text);
  761. XX            yank->ya_text = xalloc(strlen(line->li_text)+1);
  762. XX            strcpy(yank->ya_text, line->li_text);
  763. XX        }
  764. XX        else {
  765. XX            /*
  766. XX             * Yank multiple lines
  767. XX             */
  768. XX            xmit_curline();
  769. XX            yank->ya_type = YANK_LINES;
  770. XX            yank->ya_width = 0;
  771. XX            yank->ya_numlines = sc->sc_lastline-sc->sc_firstline+1;
  772. XX            if (yank->ya_text) {
  773. XX                free(yank->ya_text);
  774. XX                yank->ya_text = NULL;
  775. XX            }
  776. XX            xmit_ed("%d,%dw /tmp/yk%d.%d\n", sc->sc_firstline,
  777. XX                sc->sc_lastline, getpid(), indx);
  778. XX            yank->ya_madefile = TRUE;
  779. XX            if (indx == 0)
  780. XX                xmit_ed("%d,%dw /tmp/yk%d.%d\n",
  781. XX                    sc->sc_firstline, sc->sc_lastline,
  782. XX                        getpid(), NUM_YANK_BUFS-1);
  783.  
  784. XX            botprint(FALSE, "%d lines yanked", yank->ya_numlines);
  785. XX            hitcr_continue();
  786. XX        }
  787. XX    }
  788. XX}
  789. @//E*O*F rv_yank.c//
  790. chmod u=rw,g=rw,o=rw $OUT
  791.  
  792. echo x - rvi.1
  793. if test -f rvi.1 ; then
  794.     echo rvi.1 exists, putting output in $$rvi.1
  795.     OUT=$$rvi.1
  796.     STATUS=1
  797. else
  798.     OUT=rvi.1
  799. fi
  800. sed 's/^XX//' > $OUT <<'@//E*O*F rvi.1//'
  801. XX.TH RVI 1 
  802. XX.UC 4
  803. XX.SH NAME
  804. XXrvi \- remote screen editor based on vi
  805. XX.SH SYNOPSIS
  806. XX\fBrvi infd outfd "files"\fR
  807. XX.br
  808. XX.SH DESCRIPTION
  809. XX.I Rvi\^
  810. XXis a screen editor based on
  811. XX.IR vi .
  812. XXIt generates
  813. XX.I ed\^
  814. XXcommands for execution on a remote machine.  The parameters \fBinfd\fR and \fBoutfd\fR are
  815. XXpipe descriptors connecting
  816. XX.I rvi\^
  817. XXto a remote
  818. XX.I ed\^
  819. XXprogram.
  820. XX.PP
  821. XX.SH INVOCATION
  822. XX.I Rvi
  823. XXis invoked via an escape sequence from within a network terminal program.
  824. XXThe actual sequence varies depending on the terminal program used.  For example,
  825. XXthe escape sequence for
  826. XX.I cxint
  827. XXis \fB~v files\fR, while the escape sequence for
  828. XX.I telnet
  829. XXis \fB^]v files\fR.
  830. XX.PP
  831. XX.SH DIFFERENCES
  832. XXEntering the command \fBQ\fR allows the user to communicate directly with
  833. XX.I ed
  834. XXbypassing the
  835. XX.I rvi
  836. XXprogram.
  837. XX(To pass control back to
  838. XX.IR rvi ,
  839. XXsimply type the escape sequence again.)
  840. XX.br
  841. XX.sp
  842. XXPressing the interrupt key is synoymous with \fBQ\fR.
  843. XX.br
  844. XX.sp
  845. XXThe option \fB:set fortran\fR places
  846. XX.I rvi
  847. XXin a mode suitable for editing Fortran source files.  Tabs are expanded
  848. XXto spaces, and the first tabstop is set to column 6.  (Fortran mode is set
  849. XXimplicitly when editing files ending in \fB.f\fR)
  850. XX.br
  851. XX.sp
  852. XXCommands found in the environment variable RVINIT are executed at
  853. XXinitialization time.
  854. XX.br
  855. XX.sp
  856. XX.I Rvi
  857. XXdoes not support the following command keystrokes:
  858. XX\fBz `` = % ( ) { }\fR.
  859. XX.br
  860. XX.sp
  861. XXMacros and tags are not supported.
  862. XX.PP
  863. XX.SH "SEE ALSO"
  864. XXvi (1).
  865. XX.br
  866. XX.sp
  867. XX\f2Vi Quick Reference Card\fR.
  868. XX.br
  869. XX\f2An Introduction to Display Editing with Vi\fR,
  870. XXand
  871. XX\f2Ex Reference Manual\fR
  872. XXin the \f2\s-1UNIX\s+1 System Documentation Workbench\fR.
  873. @//E*O*F rvi.1//
  874. chmod u=rw,g=rw,o=rw $OUT
  875.  
  876. echo x - rvtest.c
  877. if test -f rvtest.c ; then
  878.     echo rvtest.c exists, putting output in $$rvtest.c
  879.     OUT=$$rvtest.c
  880.     STATUS=1
  881. else
  882.     OUT=rvtest.c
  883. fi
  884. sed 's/^XX//' > $OUT <<'@//E*O*F rvtest.c//'
  885. XX#include <stdio.h>
  886. XX#include <signal.h>
  887. XX/*
  888. XX * Loopback test.   This program forks a copy of rvi and connects it to
  889. XX * a local ``ed'' program.
  890. XX */
  891.  
  892. XXmain(argc, argv)
  893. XXint argc;
  894. XXchar **argv;
  895. XX{
  896. XX    int in[2], out[2];
  897. XX    char ibuf[12], obuf[12];
  898.  
  899. XX    if (argv[1] == NULL)
  900. XX        argv[1] = "";
  901.  
  902. XX    pipe(in);
  903. XX    pipe(out);
  904.  
  905. XX    sprintf(ibuf, "%d", in[1]);
  906. XX    sprintf(obuf, "%d", out[0]);
  907. XX    signal(SIGPIPE, SIG_IGN);
  908.  
  909. XX    if (fork() == 0) {
  910. XX        close(in[0]);
  911. XX        close(out[1]);
  912. XX        execlp("rvi", "rvi", obuf, ibuf, argv[1], "-l", NULL);
  913. XX        execl("/u/aek/bin/rvi", "rvi", obuf, ibuf, argv[1], "-l", NULL);
  914. XX        perror("exec rvi");
  915. XX        _exit(1);
  916. XX    }
  917.  
  918. XX    close(in[1]);
  919. XX    close(out[0]);
  920.  
  921. XX    close(0);
  922. XX    dup(in[0]);
  923. XX    close(1);
  924. XX    dup(out[1]);
  925.  
  926. XX    execlp("ed", "ed", NULL);
  927. XX}
  928. @//E*O*F rvtest.c//
  929. chmod u=rw,g=rw,o=rw $OUT
  930.  
  931. echo x - todo
  932. if test -f todo ; then
  933.     echo todo exists, putting output in $$todo
  934.     OUT=$$todo
  935.     STATUS=1
  936. else
  937.     OUT=todo
  938. fi
  939. sed 's/^XX//' > $OUT <<'@//E*O*F todo//'
  940. XXAdd heuristic to shut off P (prompt) in ed.
  941.  
  942. XXStrip off trailing CR's or CR-LF --> LF
  943.  
  944. XXAdd >> << %
  945. @//E*O*F todo//
  946. chmod u=rw,g=rw,o=rw $OUT
  947.  
  948. echo x - zero.c
  949. if test -f zero.c ; then
  950.     echo zero.c exists, putting output in $$zero.c
  951.     OUT=$$zero.c
  952.     STATUS=1
  953. else
  954.     OUT=zero.c
  955. fi
  956. sed 's/^XX//' > $OUT <<'@//E*O*F zero.c//'
  957. XX/*    zero - zero data structures
  958. XX    84/12/18.  A. E. Klietz.
  959. XX*/
  960.  
  961. XX#include "rv.h"
  962.  
  963. XX#ifdef zero
  964. XX#undef zero
  965. XX#endif
  966.  
  967. XX#ifndef USG
  968. XXvoid
  969. XXzero(ptr, len)
  970. XXchar *ptr;
  971. XXint len;
  972. XX{
  973. XX    for (; len > 0; --len)
  974. XX        *(ptr++) = 0;
  975. XX}
  976. XX#endif
  977. @//E*O*F zero.c//
  978. chmod u=rw,g=rw,o=rw $OUT
  979.  
  980. echo x - MANIFEST
  981. if test -f MANIFEST ; then
  982.     echo MANIFEST exists, putting output in $$MANIFEST
  983.     OUT=$$MANIFEST
  984.     STATUS=1
  985. else
  986.     OUT=MANIFEST
  987. fi
  988. sed 's/^XX//' > $OUT <<'@//E*O*F MANIFEST//'
  989. XXBUGFIX                       1
  990. XXBUGFIX2                      1
  991. XXMANIFEST                     4
  992. XXMakefile.bsd                 1
  993. XXMakefile.usg                 1
  994. XXManifest                     1
  995. XXNEXT_REL                     1
  996. XXREADME                       1
  997. XXbinsearch.c                  1
  998. XXcopy.c                       1
  999. XXcopyright                    1
  1000. XXregerror.c                   1
  1001. XXregexp.c                     1
  1002. XXregexp.h                     1
  1003. XXregmagic.h                   1
  1004. XXrv.h                         2
  1005. XXrv_change.c                  1
  1006. XXrv_cmd.c                     2
  1007. XXrv_column.c                  1
  1008. XXrv_delcol.c                  1
  1009. XXrv_delete.c                  2
  1010. XXrv_dot.c                     1
  1011. XXrv_dummy.c                   2
  1012. XXrv_edit.c                    2
  1013. XXrv_fast.c                    2
  1014. XXrv_fetch.c                   2
  1015. XXrv_flash.c                   2
  1016. XXrv_forback.c                 2
  1017. XXrv_getline.c                 2
  1018. XXrv_init.c                    2
  1019. XXrv_input.c                   2
  1020. XXrv_insert.c                  3
  1021. XXrv_join.c                    2
  1022. XXrv_linecmd.c                 3
  1023. XXrv_main.c                    2
  1024. XXrv_mark.c                    2
  1025. XXrv_misc.c                    3
  1026. XXrv_move.c                    3
  1027. XXrv_openline.c                3
  1028. XXrv_print_ln.c                2
  1029. XXrv_put.c                     3
  1030. XXrv_quit.c                    2
  1031. XXrv_redraw.c                  3
  1032. XXrv_redraw_ln.c               3
  1033. XXrv_scroll.c                  3
  1034. XXrv_scroll_bk.c               3
  1035. XXrv_search.c                  3
  1036. XXrv_shell.c                   3
  1037. XXrv_sync.c                    3
  1038. XXrv_undo.c                    3
  1039. XXrv_where.c                   4
  1040. XXrv_word.c                    4
  1041. XXrv_xmit.c                    4
  1042. XXrv_yank.c                    4
  1043. XXrvi.1                        4
  1044. XXrvtest.c                     4
  1045. XXtodo                         4
  1046. XXzero.c                       4
  1047. @//E*O*F MANIFEST//
  1048. chmod u=rw,g=rw,o=rw $OUT
  1049.  
  1050. echo Inspecting for damage in transit...
  1051. temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
  1052. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  1053. cat > $temp <<\!!!
  1054.      367     866    6288 rv_where.c
  1055.      209     594    3669 rv_word.c
  1056.       42      98     808 rv_xmit.c
  1057.      107     311    2354 rv_yank.c
  1058.       72     270    1597 rvi.1
  1059.       43      90     711 rvtest.c
  1060.        5      21      98 todo
  1061.       20      39     213 zero.c
  1062.       58     116    1798 MANIFEST
  1063.      923    2405   17536 total
  1064. !!!
  1065. wc $FILES | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  1066. if test -s $dtemp ; then
  1067.     echo "Ouch [diff of wc output]:"
  1068.     cat $dtemp
  1069.     STATUS=1
  1070. elif test $STATUS = 0 ; then
  1071.     echo "No problems found."
  1072. else
  1073.     echo "WARNING -- PROBLEMS WERE FOUND..."
  1074. fi
  1075. exit $STATUS
  1076.